﻿using System;
namespace Xtee.XteeClient.Doc {
    using global::Doc.Xroad.Eu;
    using global::Doc.Xroad.Eu.Messages;
    using global::Xtee.Core;
    using System.Collections.Generic;
    
    
    public class DocAdapter {
        
        private string _protocolVersion = "4.0";
        
        private Xtee.Core.Client.IXteeCommand _xteeCommand;
        
        public DocAdapter() : 
                this(new Xtee.Core.Client.XteeCommand(new Xtee.Core.Client.Config.Configuration())) {
        }
        
        public DocAdapter(Xtee.Core.Client.IXteeCommand command) {
            this._xteeCommand = command;
        }
        
        public virtual Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType Service {
            get {
                return new Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType(){ObjectType = "SERVICE", XRoadInstance = "EE",MemberClass = "GOV", MemberCode = "700030", SubsystemCode = "doc"};
            }
        }
        
        public virtual string ProtocolVersion {
            get {
                return this._protocolVersion;
            }
            set {
                this._protocolVersion = value;
            }
        }
        
        public virtual Xtee.Core.Client.IXteeCommand XteeCommand {
            get {
                return this._xteeCommand;
            }
            set {
                this._xteeCommand = value;
            }
        }
        
        public virtual global::Doc.Xroad.Eu.Messages.GetDocumentResponse GetDocument(string id) {
            var getDocumentInputHeader = new global::Doc.Xroad.Eu.Headers.GetDocumentInputHeader();
            getDocumentInputHeader.Client = _xteeCommand.Configuration.Client;
            getDocumentInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            getDocumentInputHeader.ProtocolVersion = this.ProtocolVersion;
            getDocumentInputHeader.Service = Service;
            getDocumentInputHeader.Service.ServiceCode = "GetDocument";
            getDocumentInputHeader.Service.ServiceVersion = null;
            getDocumentInputHeader.UserId = _xteeCommand.Configuration.UserId;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://doc.x-road.eu/"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "GetDocument", getDocumentInputHeader, new global::Doc.Xroad.Eu.Messages.GetDocumentRequest(id)));
            return ((global::Doc.Xroad.Eu.Messages.GetDocumentResponse)(responseEnvelope.Body));
        }
        
        public virtual void AddDocument(global::Doc.Xroad.Eu.Document document) {
            var addDocumentInputHeader = new global::Doc.Xroad.Eu.Headers.AddDocumentInputHeader();
            addDocumentInputHeader.Client = _xteeCommand.Configuration.Client;
            addDocumentInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            addDocumentInputHeader.ProtocolVersion = this.ProtocolVersion;
            addDocumentInputHeader.Service = Service;
            addDocumentInputHeader.Service.ServiceCode = "AddDocument";
            addDocumentInputHeader.Service.ServiceVersion = null;
            addDocumentInputHeader.UserId = _xteeCommand.Configuration.UserId;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://doc.x-road.eu/"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "AddDocument", addDocumentInputHeader, new global::Doc.Xroad.Eu.Messages.AddDocumentRequest(document)));
        }
        
        public virtual global::Doc.Xroad.Eu.Messages.GetDocumentListResponse GetDocumentList() {
            var getDocumentListInputHeader = new global::Doc.Xroad.Eu.Headers.GetDocumentListInputHeader();
            getDocumentListInputHeader.Client = _xteeCommand.Configuration.Client;
            getDocumentListInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            getDocumentListInputHeader.ProtocolVersion = this.ProtocolVersion;
            getDocumentListInputHeader.Service = Service;
            getDocumentListInputHeader.Service.ServiceCode = "GetDocumentList";
            getDocumentListInputHeader.Service.ServiceVersion = null;
            getDocumentListInputHeader.UserId = _xteeCommand.Configuration.UserId;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://doc.x-road.eu/"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "GetDocumentList", getDocumentListInputHeader, new global::Doc.Xroad.Eu.Messages.GetDocumentListRequest()));
            return ((global::Doc.Xroad.Eu.Messages.GetDocumentListResponse)(responseEnvelope.Body));
        }
    }
}
